
import registnet.dao.CourseOfferingPeer;
import registnet.dao.CoursePeer;
import registnet.dao.Student;
import registnet.dao.StudentPeer;
import registnet.dao.SlotPeer;
		
import resources.Constants;

registnet.dao.SystemPropertiesPeer spp = new registnet.dao.SystemPropertiesPeer();
/* [start] 	initializes gui variables */
String _gradesheet = bundle.getProperty("registnet.module.grades.gradesheet");

String _academic_year = bundle.getProperty("registnet.module.grades.macro.gradesheet.search.academic_year");
String _semester = bundle.getProperty("registnet.module.grades.macro.gradesheet.search.semester");
String _course = bundle.getProperty("registnet.module.grades.macro.gradesheet.search.course");
String _section = bundle.getProperty("registnet.module.grades.macro.gradesheet.search.section");

String _student_number = bundle.getProperty("registnet.module.grades.macro.gradesheet.form.student_number");
String _full_name = bundle.getProperty("registnet.module.grades.macro.gradesheet.form.full_name");
String _sex = bundle.getProperty("registnet.module.grades.macro.gradesheet.form.sex");
String _college = bundle.getProperty("registnet.module.grades.macro.gradesheet.form.college");
String _degree_course = bundle.getProperty("registnet.module.grades.macro.gradesheet.form.degree_course");

List courses = new CoursePeer().getCoursesByUnit(new UnitPeer().getUnitId(_office));
/* [end] */		



/* [start]	defines a renderer for the grades */
private class ClassListRenderer implements RowRenderer  {
	public void render(Row row, java.lang.Object data) {
		new Label(data[0]).setParent(row);
		new Label(data[1]).setParent(row);
		new Label(data[2]).setParent(row);
		new Label(data[3]).setParent(row);
		new Label(data[4]).setParent(row);
		new Label(data[5]).setParent(row);
	}
}
/* [end] */



/* [start] 	retrieves the grades and places them on the listbox */
void retrieveClassList(){
	String courseValue = course_code.value;
	String sectionValue = section.value;
	int semester = spp.getSystemProperties().getSemester();
	int year = spp.getSystemProperties().getAcademicYear();
	if(semester==3){
		year++;
	}
	
	Integer courseOfferingId = new CourseOfferingPeer().getCourseOfferingId(new CoursePeer().getCourseId(courseValue), sectionValue, semester, year);
	if(courseOfferingId==null){
		alert("Section not found.");
		return;
	}
	
	List classlist = new SlotPeer().getStudentsByCourseOffering(courseOfferingId);
	ListIterator iter = classlist.listIterator();
	String[][] listModel = new String[classlist.size()][6];
	int i = 0;
	while(iter.hasNext()){
		Slot slot = iter.next();
		Student student = new StudentPeer().getStudent(slot.getStudentId());
		listModel[i][0] = "" + (i + 1);
		listModel[i][1] = student.getStudentNumber();
		listModel[i][2] = student.getLastName() + ", " + student.getFirstName() + " " + student.getMiddleName();
		listModel[i][3] = student.getSex();
		registnet.dao.DegreeCourse dp = new registnet.dao.DegreeCoursePeer().getDegreeCourse(student.getCurriculum().getDegreeId());
		listModel[i][4] = new registnet.dao.CollegePeer().getCollege(dp.getCollegeId()).getCollegeCode();
		listModel[i][5] = dp.getDegreeCode();
		i++;
	}
	ListModel strset = new SimpleListModel(listModel);
	contents_win.getFellow("classlist_g").setModel(strset);
	contents_win.getFellow("classlist_g").setRowRenderer(new ClassListRenderer());
	
}
/* [end] */



/* [start]	defines a renderer for the grades */
public class SectionRenderer implements ListitemRenderer {
	public void render(Listitem item, java.lang.Object data) {
		new Listcell(data).setParent(item);
	}
}
/* [end] */

public class UIItemRenderer implements ListitemRenderer {
	public void render(Listitem item, java.lang.Object data) {
		new Listcell(data).setParent(item);
	}
}
void retrieveCourses(){											  
	String[] listModel = new String[courses.size()];
	for (int i=0; i<courses.size(); i++)
		listModel[i] = courses.get(i).getCourseCode();
	ListModel strset = new ListModelList(listModel);
	course_code_lb.setModel(strset);
	course_code_lb.setItemRenderer(new UIItemRenderer());
}

void filterCourse(String string){
	ListIterator i = courses.listIterator();
	List list = new java.util.Vector();
	while(i.hasNext()){
		String temp = i.next().getCourseCode(); 
		if(temp.toUpperCase().startsWith(string.toUpperCase())){
			list.add(temp);
		}
	}
	course_code_lb.getModel().clear();
	course_code_lb.getModel().addAll(list);
}

/* [start] 	retrieves the sections and places them on the listbox */
void retrieveSections(){
	String courseValue = course_code.value;
	int semester = spp.getSystemProperties().getSemester();
	int year = spp.getSystemProperties().getAcademicYear();
	if(semester==3){
		year++;
	}
	List sections = new CourseOfferingPeer().getCourseOfferingNames(new CoursePeer().getCourseId(courseValue), year, semester);
	
	ListModel strset = new ListModelList(sections);
	section_lb.setModel(strset);
	section_lb.setItemRenderer(new SectionRenderer());
}
/* [end] */




